<?php
namespace app\index\controller;

use Endroid\QrCode\QrCode;

use think\Controller;

/**
 * 二维码生成
 *
 * @author leolei <346991581@qq.com>
 */
class Index extends Controller
{

    /**
     * 网站入口
     */
    public function index()
    {
        ob_end_clean(); //清除缓存
        $qrCode = new QrCode();
        $qrCode
            ->setText(time())
            ->setSize(300)
            ->setPadding(10)
            ->setErrorCorrection('high')
            ->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
            ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0])
            ->setLabel('Scan the code')
            ->setLabelFontSize(16)
            ->setImageType(QrCode::IMAGE_TYPE_PNG)
        ;
        header('Content-Type: '.$qrCode->getContentType());
        $qrCode->render();
    }
}
